// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Talina Gaming System (TgS) (∂)
//  »File«      TgS Common - Base - API [F].i_inc
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, Andrew Aye.  All Rights Reserved.
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //

TgINLINE TgVOID F(tgCM_SWP)( PCU_TYPE pA, PCU_TYPE pB )
{
    const TYPE uiTemp = *pA;
    *pA = *pB;
    *pB = uiTemp;
}


TgINLINE TYPE F(tgCM_SGN)( const TYPE fA )
{
    return (( fA > MKL(0.0) ) ? MKL(1.0) : (( fA < MKL(0.0) ) ? MKL(-1.0) : MKL(0.0) ));
}


TgINLINE TYPE F(tgCM_MAX)( const TYPE fA, const TYPE fB )
{
    return (F(tgPM_FSEL)(fA - fB, fA, fB));
}


TgINLINE TYPE F(tgCM_MIN)( const TYPE fA, const TYPE fB )
{
    return (F(tgPM_FSEL)(fB - fA, fA, fB));
}


TgINLINE TYPE F(tgCM_CLP)( const TYPE fA, const TYPE fLow, const TYPE fHigh )
{
    return (F(tgPM_FSEL)(fLow - fA, fLow, F(tgPM_FSEL)(fHigh - fA, fA, fHigh)));
}


TgINLINE TYPE F(tgCM_CLP_MIN)( const TYPE fA, const TYPE fLow )
{
    return (F(tgPM_FSEL)(fLow - fA,fA,fLow));
}


TgINLINE TYPE F(tgCM_CLP_MAX)( const TYPE fA, const TYPE fHigh )
{
    return (F(tgPM_FSEL)(fA - fHigh,fA,fHigh));
}


TgINLINE TgBOOL F(tgCM_NaN)( const TYPE fA )
{
#if defined(_MSC_VER)
    return (!_finite(fA));
#else
    return (isnan(fA));
#endif
}


TgINLINE TgBOOL F(tgCM_NR0)( const TYPE fA )
{
    return (!F(tgCM_NaN)(fA) && (F(tgPM_ABS)(fA) <= F(TgROOT_EPS)));
}


TgINLINE TgBOOL F(tgCM_NR1)( const TYPE fA )
{
    return (!F(tgCM_NaN)(fA) && (F(tgPM_ABS)(F(tgPM_ABS)(fA) - MKL(1.0)) <= F(TgROOT_EPS)));
}


TgINLINE TYPE F(tgCM_CLP_FRC)( const TYPE fA, const TYPE fB )
{
    return (F(tgPM_FSEL)( fA, F(tgPM_FSEL)( fA - fB, 1.0F, fA / fB ), MKL(0.0) ));
}


TgINLINE TYPE F(tgCM_LRP)( const TYPE fA, const TYPE fB, const TYPE fdT )
{
    return (fA + fdT*(fB - fA));
}


TgINLINE TgBOOL F(tgCM_EQ)( const TYPE fA, const TYPE fB, const TYPE fTol )
{
    register const TYPE                     tyABS_A = F(tgPM_ABS)(fA);
    register const TYPE                     tyABS_B = F(tgPM_ABS)(fB);

    if (tyABS_B > F(TgEPS))
    {
        return (F(tgPM_ABS)( (tyABS_A / tyABS_B) - MKL(1.0)) < F(TgEPS));
    }
    else if (tyABS_A > F(TgEPS))
    {
        return (F(tgPM_ABS)( (tyABS_B / tyABS_A) - MKL(1.0)) < F(TgEPS));
    }
    else
    {
        return (TgTRUE);
    };
}